package com.minelx.datamicroscope.querylanguage.data.sql;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CollectingJoinPoint {

	private final List<ConditionProvider> conditionProviders;

	private final AliasedTablesBuilder aliasedTablesBuilder;

	private CollectingJoinPoint(List<ConditionProvider> conditionProviders, AliasedTablesBuilder aliasedTablesBuilder) {
		this.conditionProviders = conditionProviders;
		this.aliasedTablesBuilder = aliasedTablesBuilder;
	}

	public Map<String, String> collectingOnKeyMapping() {
		Map<String, String> result = new HashMap<>();
		for (ConditionProvider conditionProvider : conditionProviders) {
			String resourceName = aliasedTablesBuilder.addJoiningCollect(conditionProvider.right());
			result.put(resourceName, conditionProvider.left().fieldName());
		}
		return result;
	}

	public static CollectingJoinPoint create(List<ConditionProvider> literalConditions, AliasedTablesBuilder aliasedTablesBuilder) {
		return new CollectingJoinPoint(literalConditions, aliasedTablesBuilder);
	}
}
